import asyncio
import time

import websockets


async def start_c():
    # 与WebSocket服务器建立连接
    async with websockets.connect("ws://localhost:8080", ping_interval=200, ping_timeout=200,
                                  timeout=2000) as websocket:
        while True:
            msg = input("please input: ")
            await websocket.send(msg)

            # 等待服务器返回响应消息
            message = await websocket.recv()
            print(f"[{time.asctime()}from server]: {message}")


if __name__ == '__main__':
    asyncio.run(start_c())
